/*
1.定义枚举等级
2.提供日志等级转字符串接口
*/

#ifndef _LEVEL_HPP_
#define _LEVEL_HPP_

#include <iostream>
#include <string>

namespace xzt
{
    namespace log
    {
        class Level
        {
        public:
            enum class value
            {
                UNKNOWN = 0,
                DEBUG,
                INFO,
                WARN,
                ERROR,
                FATAL,
                OFF  // 用于关闭日志输出
            };

            static value fromNumber(int num)
            {              
                switch(num)
                {
                    case 0: return value::UNKNOWN;
                    case 1: return value::DEBUG;
                    case 2: return value::INFO;
                    case 3: return value::WARN;
                    case 4: return value::ERROR;
                    case 5: return value::FATAL;
                    case 6: return value::OFF;
                    default: return value::UNKNOWN;
                }
            }

            static std::string toString(value level)
            {
                #define TO_STRING(x) case value::x: return #x
                
                switch(level)
                {
                    TO_STRING(UNKNOWN);
                    TO_STRING(DEBUG);
                    TO_STRING(INFO);
                    TO_STRING(WARN);
                    TO_STRING(ERROR);
                    TO_STRING(FATAL);
                    TO_STRING(OFF);
                    default: return "UNKNOWN";
                }
            }
        };
    }
}






#endif // _LEVEL_HPP_